package com.ruoyi.yipaiju.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yipaiju.domain.ModelConfig;
import com.ruoyi.yipaiju.service.IModelConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 首页模块配置Controller
 * 
 * @author liuwp
 * @date 2023-03-27
 */
@RestController
@RequestMapping("/yipaiju/model_config")
public class ModelConfigController extends BaseController
{
    @Autowired
    private IModelConfigService modelConfigService;

    /**
     * 查询首页模块配置列表
     */
    @PreAuthorize("@ss.hasPermi('yipaiju:model_config:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelConfig modelConfig)
    {
        startPage();
        List<ModelConfig> list = modelConfigService.selectModelConfigList(modelConfig);
        return getDataTable(list);
    }

    /**
     * 导出首页模块配置列表
     */
    @PreAuthorize("@ss.hasPermi('yipaiju:model_config:export')")
    @Log(title = "首页模块配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelConfig modelConfig)
    {
        List<ModelConfig> list = modelConfigService.selectModelConfigList(modelConfig);
        ExcelUtil<ModelConfig> util = new ExcelUtil<ModelConfig>(ModelConfig.class);
        util.exportExcel(response, list, "首页模块配置数据");
    }

    /**
     * 获取首页模块配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('yipaiju:model_config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(modelConfigService.selectModelConfigById(id));
    }

    /**
     * 新增首页模块配置
     */
    @PreAuthorize("@ss.hasPermi('yipaiju:model_config:add')")
    @Log(title = "首页模块配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ModelConfig modelConfig)
    {
        return toAjax(modelConfigService.insertModelConfig(modelConfig));
    }

    /**
     * 修改首页模块配置
     */
    @PreAuthorize("@ss.hasPermi('yipaiju:model_config:edit')")
    @Log(title = "首页模块配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ModelConfig modelConfig)
    {
        return toAjax(modelConfigService.updateModelConfig(modelConfig));
    }

    /**
     * 删除首页模块配置
     */
    @PreAuthorize("@ss.hasPermi('yipaiju:model_config:remove')")
    @Log(title = "首页模块配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(modelConfigService.deleteModelConfigByIds(ids));
    }
}
